home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlb20 / lib / spawnvp.c < prev    next >
C/C++ Source or Header  |  1991-04-15  |  989b  |  48 lines

  1. /* spawnvp, spawnlp: try to execute a program on the default system
  2.    execution path. WARNING: the current directory is always searched
  3.    first.
  4.  
  5.    Written by Eric R. Smith and placed in the public domain.
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <process.h>
  10. #include <stdarg.h>
  11. #include <errno.h>
  12.  
  13. __EXTERN char *    findfile __PROTO((char *, char *, char **));
  14.  
  15.  
  16. static char *extensions[] = { "ttp", "prg", "tos", NULL };
  17.  
  18. int
  19. spawnvp(mode, name, argv)
  20.     int mode;
  21.     char *name;
  22.     char **argv;
  23. {
  24.     char *execname;
  25.  
  26.     execname = findfile(name, getenv("PATH"), extensions);
  27.     if (!execname) {
  28.         errno = ENOENT;
  29.         return -1;        /* file not found */
  30.     }
  31.     return spawnve(mode, execname, argv, (char **)NULL);
  32. }
  33.  
  34. #ifdef __STDC__
  35. int spawnlp(int mode, char *name, ...)
  36. #else
  37. int spawnlp(mode, name) int mode; char *name;
  38. #endif
  39. {
  40.     va_list args;
  41.     int r;
  42.  
  43.     va_start(args, name);
  44.     r = spawnvp(mode, name, (char **)args);
  45.     va_end(args);
  46.     return r;
  47. }
  48.